<?php
/**
 *采购模型
 */
class Base_Model_Product extends Model_Base {
	/**
	 * 获取产品已经清仓的仓库名称
	 * @param  [type] $goodsSn [description]
	 * @return [type]
	 */
	public function getGoodsEmptyWarehouse($goodsSn) {
		$goodsSn = is_array($goodsSn) ? $goodsSn : array($goodsSn);
		$this->db = $this->db();
		$where = $this->db->quoteInto("p.goods_sn in(?)", $goodsSn);
		$where .= " AND " . $this->db->quoteInto(" p.is_clearance=?", 1);
		$sql = 'select p.goods_sn,p.warehouse,w.warehouse_name from p_warehouse_product as p
              left join c_warehouse as w on p.warehouse=w.warehouse_code where ' . $where;

		$hasEmptyWarehouse = $this->db->fetchAll($sql);
		$result = [];
		foreach ($hasEmptyWarehouse as $warehouse) {
			$result[$warehouse['goods_sn']][] = $warehouse['warehouse_name'];
		}
		return $result;
	}

	/**
	 * 获取产品的新品仓库名称
	 * @param  [type] $goodsSn [description]
	 * @return [type]
	 */
	public function getGoodsNewWarehouse($goodsSn) {
		$goodsSn = is_array($goodsSn) ? $goodsSn : array($goodsSn);
		$this->db = $this->db();
		$where = $this->db->quoteInto("p.goods_sn in(?)", $goodsSn);
		$where .= " AND " . $this->db->quoteInto(" p.is_new=?", 1);
		$sql = 'select p.goods_sn,p.warehouse,w.warehouse_name from p_warehouse_product as p
              left join c_warehouse as w on p.warehouse=w.warehouse_code where ' . $where;

		$hasEmptyWarehouse = $this->db->fetchAll($sql);
		$result = [];
		foreach ($hasEmptyWarehouse as $warehouse) {
			$result[$warehouse['goods_sn']][] = $warehouse['warehouse_name'];
		}
		return $result;
	}

	/**
	 * 取商品的名称
	 * @param $goods_sn
	 * @return Array()
	 */
	public function getProduct($goods_sn) {

		return $this->db()->fetchRow('SELECT goods_name, product_name, product_status, edit_status, UNIX_TIMESTAMP(shelf_time) as shelf_time FROM p_product WHERE goods_sn = "' . $goods_sn . '"');
	}
}